<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>视频管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/iconfont.css">
    <link rel="stylesheet" href="../lib/layui/css/layui.css" media="all">

    <link rel="stylesheet" href="../css/xadmin.css">
    <script src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <script src="../js/base.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        tr td,
        tr th {
            text-align: center !important;
            border: none !important;
        }

        tr td {
            border-bottom: 1px solid #eee !important;
            border-top: 1px solid #eee !important;
        }
    </style>
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card" style="display: flex;justify-content: space-between;">
                    <div class="layui-card-body ">
                        <blockquote class="layui-elem-quote" style="border:0;font-size: 18px;color: #000;">视频管理
                        </blockquote>
                    </div>
                    <div class="layui-card-body " style="display: flex;">
                        <blockquote style="cursor: pointer" class="layui-elem-quote"
                            onclick="xadmin.open('新增视频','add_video.html',600,600)"><i
                                class="layui-icon">&#xe654;</i>新增视频
                        </blockquote>
                    </div>
                </div>
            </div>
            <div class="layui-col-md12">
                <div class="layui-card">
                    <!-- <div class="layui-card-header">数据统计</div> -->
                    <div class="layui-fluid">
                        <div class="layui-row layui-col-space15">
                            <div class="layui-col-md12">
                                <div class="layui-card-body " style="display: flex;justify-content:space-between">
                                    <form class="layui-form" action="">
                                        <div class="layui-inline layui-show-xs-block">
                                            <select id="type" name="type">
                                                <option value="">全部</option>
                                                <option value="1">基本功教学</option>
                                                <option value="2">颠球教学</option>
                                                <option value="3">技巧教学</option>
                                                <option value="4">踢球方法</option>
                                                <option value="5">内侧踢球</option>
                                                <option value="6">接球带球</option>
                                                <option value="7">头球技术</option>
                                                <option value="8">守门员技术</option>
                                            </select>
                                        </div>
                                        <div class="layui-inline layui-show-xs-block">
                                            <button class="layui-btn search" data-type="reload"
                                                lay-filter="add">搜索</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-card-body layui-table-body layui-table-main">

                <!-- 表格部分开始 -->
                <table id="video_table" lay-filter="test" lay-data="{id: 'testReload'}"></table>
                <script type="text/html" id="barDemo">
                    <!--<a lay-event="detail" class="btn_a layui-btn layui-btn-primary layui-btn-xs">查看</a>-->
                <a lay-event="edit" class="btn_a layui-btn layui-btn-xs">修改</a>
                <a lay-event="del" class="btn_a layui-btn layui-btn-danger layui-btn-xs">删除</a>
                </script>
                <!-- 表格结束 -->
            </div>
        </div>
    </div>
    </div>
</body>

</html>

<script>
    layui.use('table', function () {
        var table = layui.table;
        var form = layui.form;

        var index = layer.load(1); //添加laoding,0-2两种方式

        //第一个实例
        var ins1 = table.render({
            elem: '#video_table', //指定原始表格元素选择器（推荐id选择器）
            // height: 600,
            width: "100%",
            // 附加参数，post token
            // where: { 'token': token },
            loading: true,
            method: 'get',
            url: video_manage, //数据接口
            page: true, //开启分页
            // toolbar: 'default', //开启工具栏，此处显示默认图标
            cols: [
                [ //表头
                    // { type: 'checkbox', fixed: 'left' },
                    {
                        field: 'id',
                        title: 'ID',
                        width: 150
                    },
                    {
                        field: 'title',
                        title: '标题',
                        width: 150
                    },
                    {
                        field: 'type',
                        title: '视频类型',
                        width: 150,
                        templet: function (d) {
                            if (d.type == "1") {
                                return "基本功教学"
                            } else if (d.type == "2") {
                                return "颠球教学"
                            } else if (d.type == "3") {
                                return "技巧教学"
                            } else if (d.type == "4") {
                                return "踢球方法"
                            } else if (d.type == "5") {
                                return "内侧踢球"
                            } else if (d.type == "6") {
                                return "接球带球"
                            } else if (d.type == "7") {
                                return "头球技术"
                            } else if (d.type == "8") {
                                return "守门员技术"
                            }
                        }
                    },
                    {
                        field: 'imgUrl',
                        title: '视频封面',
                        width: 150,
                        templet: function (d) {
                            if (d.imgUrl != "" && d.imgUrl != null) {
                                return "<div onclick='show_img(this)' ><img src='" + d.imgUrl +
                                    "'></div>'"
                            } else {
                                return ""
                            }
                        }
                    },
                    {
                        field: 'name',
                        title: '发布人',
                        width: 150
                    },
                    {
                        fixed: 'right',
                        title: "操作",
                        width: 400,
                        align: 'center',
                        toolbar: '#barDemo'
                    }
                ]
            ],
            id: 'testReload',
            done: function (res) {
                layer.close(index)
                if (res.msg == "2") {
                    parent.window.location.href = getRequestPrefix() + "/footBallAdmin/login.html"
                }
            }
        });


        //头部输入框筛选功能
        var $ = layui.$,
            active = {

                reload: function () {

                    var type = $('#type');
                    // 执行重载（重新加载数据表格）
                    table.reload('testReload', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        },
                        where: {
                            "type": type.val(),
                        }
                    }, 'data');
                }
            };


        //给查询添加点击事件
        $('.search').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
            //一定要阻止表单的默认行为（刷新）
            return false
        });


        //监听头工具栏事件


        //监听点击的按钮，获取行信息
        table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            //获得当前行数据
            var $ = layui.$
            var data = obj.data,
                layEvent = obj.event; //获得 lay-event 对应的值
            // if (layEvent === 'detail') {
            //     // layer.msg('查看操作');
            //     layer.open({
            //         content:"car_detail.html",
            //         type:2,
            //         area:["400px","480px"],
            //         title:"车辆信息",
            //         // shade:true,
            //         shadeClose:true,
            //         success:function(layero,index){
            //             console.log(data)//获取点击行的数据
            //             var body = layer.getChildFrame('body', index);
            //             var iframeWin = window[layero.find('iframe')[0]['name']];
            //             body.find('.car_name').text(data.carName)
            //             body.find('.car_brand').text(data.carBrand)
            //             body.find('.car_type').text(data.carType)
            //             body.find('.car_num').text(data.carNumber)
            //             body.find('.car_driver').text(data.chauffeur)
            //             body.find('.driver_tel').text(data.chauffeurPhone)
            //             body.find('.car_code').text(data.carNo)
            //         }
            //     })
            //     // console.log(data)
            // } else
            if (layEvent === "edit") {
                // layer.msg('修改操作');
                layer.open({
                    content: "edit_video.html",
                    type: 2, //打开的窗口的类型
                    area: ["600px", "600px"],
                    title: "修改视频",
                    // btn: ['确认', '取消'],//开启显示按钮功能
                    // btnAlign: 'c',//居中显示按钮
                    // shade:true,
                    shadeClose: true,
                    success: function (layero, index) {
                        // console.log(data)//获取点击行的数据,获取打开的iframe

                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        console.log(iframeWin, "子窗口对象")
                        //行信息数据回显
                        console.log(data, "行信息")
                        body.find('#title').val(data.title)
                        body.find('#content').text(data.content)
                        body.find('#videoUrl').attr("src", data.vipUrl)
                        body.find('input[name="isHomeDisplay"]').eq(data.isHomeDisplay)
                            .attr("checked", "checked")
                        body.find('#url').val(data.vipUrl)
                        body.find('#id').val(data.id)
                        //类型回显
                        body.find("#type option").each(function (index, item) {
                            if (item.value == data.type) {
                                $(this).attr("selected", true)
                                $("#type").attr("value", item.text)
                            }
                        })
                        iframeWin.layui.form.render()
                    }
                })
            } else if (layEvent === "del") {
                layer.confirm('真的删除行么', function (index) { //点击确定后，才执行下面语句
                    $.ajax({
                        type: "get",
                        url: delVideo,
                        data: {
                            id: data.id
                        },
                        success: function (res) {
                            // console.log(res,"2da42da2ad12ad42da4")
                            if (res.msg == 0) {
                                //删除成功
                                layer.alert("删除成功")
                                // console.log(index, data);//获取行信息
                                obj.del(); //删除对应行（tr）的DOM结构
                                layer.close(index);
                                table.reload('testReload', {
                                    page: {
                                        curr: 1 //重新从第 1 页开始
                                    }
                                }, 'data');
                            } else {
                                layer.msg(res.msg)
                            }
                        }
                    })

                    //向服务端发送删除指令
                });
            }
        });

    });

    /**
     * 点击放大图片
     * @param t
     */
    function show_img(t) {
        var t = $(t).find("img");
        //页面层
        layer.open({
            type: 1,
            skin: 'layui-layer-rim', //加上边框
            area: ['70%', '80%'], //宽高
            shadeClose: true, //开启遮罩关闭
            end: function (index, layero) {
                return false;
            },
            content: '<div style="text-align:center;width:100%;height: 100%;overflow: hidden"><img src="' + $(t)
                .attr('src') + '" style="width:100%;height: 100%;display: block;margin: 0 auto;"/></div>'
        });
    }
</script>